import React from 'react';

// 组件数据子传父：实现点击按钮组件，改变颜色

function Btn1(props) {
  const obj = { color: 'red' };
  return <button onClick={() => props.aa(obj)}>按钮1-变红</button>;
}

function Btn2(props) {
  const obj = { color: 'blue' };
  return <button onClick={() => props.bb(obj)}>按钮2-变蓝</button>;
}

class App extends React.Component {
  state = {
    color: 'green'
  };

  changeColor = (obj) => {
    this.setState({ color: obj.color });
  };

  render() {
    return <div>
      <Btn1 aa={this.changeColor} ></Btn1>
      <Btn2 bb={this.changeColor}></Btn2>
      <div style={{ backgroundColor: this.state.color }}>父组件的某个盒子</div>
    </div>;
  }
}

export default App;
